<template>
    <div>
    <subcate :data='catelist' />
        <van-field
    v-model="name"
    name="名称"
    label="名称"
    placeholder="名称"
    :rules="[{ required: true, message: '请填写名称' }]"/>
        <van-field
    v-model="description"
    name="描述"
    label="描述"
    placeholder="描述"/>
        <van-field
    v-model="tname"
    name="讲师"
    label="讲师"
    placeholder="讲师"/>
        <van-image
  width="100"
  height="100"
  :src="pic"/>
  图片上传：<van-uploader :after-read="afterRead"/><br>
  视频上传：<van-uploader :after-read="afterReadVedio" v-model="filelist" multiple :max-count="3" accept=".mp4"/><br>
  <van-button type='primary' @click="add">添加</van-button>
    </div>
</template>

<script>
// 导入子组件
import subcate from '@/components/try/subcate'
    export default {
           //注册子组件
        components:{
            'subcate':subcate
        },
        data(){
            return{
                name:'',
                description:"",
                tname:"",
                pic:'http://localhost:5000/static/upload/',
                filelist:[],
                catelist:[],
                cid:0,
                vedios:[]
            }
        },
        methods:{
            //图片
            afterRead(File,type=1){
                let data = new FormData()
                data.append('id',1)
                data.append('file',file.file)
                this.$axios.post('upload',data).then(res=>{
                    //视频
                    if (type==2){
                        this.vedios.push(res.data.pic)
                    }else{
                        this.pic = 'http://localhost:5000/static/upload/'+res.data.pic
                    }
                })
            },
            afterReadVedio(){
            //遍历Filelist
            for(var i =0;i<this.fileList.length;i++){
                this.afterRead(this.fileList[i],2)
            }
        },
            get_catelist(){
                this.$axios.get('cateM').then(res=>{
                    this.catelist = res.data.list
                })
            },
            //获取选中的分类id 
            getcid(v){
                // 更新分类ID
                this.cid=v
            },
            add(){
                this.$axios.post('')
            },
    },
    mounted(){
        // this.get_catelist()
    }
    }
</script>

<style scoped>

</style>